package com.company.lagou.homework.homework1;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Hashjihe {

    public static void main(String[] args) {

        // 准备一个Map集合
        Map<String, Integer> m1 = new HashMap<>();
        // 准备一个字符串
        String str1 = new String("123, 456, 789, 123, 456");
        // 进行拆分
        String[] sArr = str1.split(",");

        for (int i = 0; i < sArr.length; i++) {
            if (!m1.containsKey(sArr[i])) {
                m1.put(sArr[i], 1);
            } else {
                m1.put(sArr[i], m1.get(sArr[i]) + 1);
            }
        }
        System.out.println("m1 = " + m1);
        // 获取Map遍历
        Set<Map.Entry<String, Integer>> s1 = m1.entrySet();
        for (Map.Entry<String, Integer> me1 : s1) {
            System.out.println(me1);
            System.out.println(me1.getKey() + "出现了" + me1.getValue() + "次");

        }

    }
}

